package com.calm.cdemo.anim;

import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;

import com.calm.cdemo.R;
import com.calm.cdemo.base.BaseActivity;

/**
 * Create by Calm
 * 2020/3/3 17:07
 * 帧动画就像放动画片一样，一张张的播放出来
 */
public class FrameAnim extends BaseActivity implements View.OnClickListener {
    private AnimationDrawable animationDrawable;
    @Override
    protected void init() {
        ImageView imageView = findViewById(R.id.ivFrameAnim);
        animationDrawable = (AnimationDrawable) imageView.getBackground();
        findViewById(R.id.start).setOnClickListener(this);
        findViewById(R.id.stop).setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.frameanim;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.start:
                if(animationDrawable != null && !animationDrawable.isRunning()){
                    animationDrawable.start();
                }
                break;
            case R.id.stop:
                if(animationDrawable != null && animationDrawable.isRunning()){
                    animationDrawable.stop();
                }
                break;
        }
    }
}
